package com.gg.zjj.controller;

import com.gg.common.pojo.MManufacture;
import com.gg.common.pojo.MProcedureModule;
import com.gg.zjj.pojo.MProcedureModuleView;
import com.gg.zjj.pojo.SubmitOperationView;
import com.gg.zjj.service.MManufactureService;
import com.gg.zjj.util.Result;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author koco
 * 2022/10/19
 * 15:49
 */
@Controller
@RequestMapping("/zjj/")
public class ProductionDispatchWorkOrderReviewController {

    @Resource
    private MManufactureService manufactureService;

    @RequestMapping("queryAllPendingProductionDispatchOrders.action")
    @ResponseBody
    private Result<List<MManufacture>> queryAllPendingProductionDispatchOrders() {
        return Result.success(manufactureService.queryAllPendingProductionDispatchOrdersService());
    }

    @RequestMapping("queryPendingProductionDispatchOrders.action")
    @ResponseBody
    private Result<MManufacture> queryPendingProductionDispatchOrders(@RequestBody String manufactureId) {
        return Result.success(manufactureService.queryPendingProductionDispatchOrders(manufactureId));
    }


    @RequestMapping("approvedWorkOrder.action")
    @ResponseBody
    private Result approvedWorkOrder(@RequestBody String inboundOrder) {
        MProcedureModuleView view =(MProcedureModuleView)JSONObject.toBean(JSONObject.fromObject(inboundOrder), MProcedureModuleView.class);
        List<MProcedureModule> list=new ArrayList<>();
        for (int i = 0; i < view.getProductionMaterial().size(); i++) {
            MProcedureModule procedure = (MProcedureModule) JSONObject.toBean(JSONObject.fromObject(view.getProductionMaterial().get(i)), MProcedureModule.class);
            list.add(procedure);
        }
        view.setProductionMaterial(list);
        return manufactureService.examinationPassed(view);
    }

    @RequestMapping("productionDispatcherRefused.action")
    @ResponseBody
    private Result productionDispatcherRefused(@RequestBody String workOrderNumber) {
        return manufactureService.productionDispatcherRefused(workOrderNumber);
    }

    @RequestMapping("queryAllProductionSummaries.action")
    @ResponseBody
    private Result<List<MManufacture>> queryAllProductionSummaries() {
        return Result.success(manufactureService.queryAllProductionSummaries());
    }

    @RequestMapping("submitOperation.action")
    @ResponseBody
    private Result submitOperation(@RequestBody String SubmitOperationView) {
        return manufactureService.submitOperationService((com.gg.zjj.pojo.SubmitOperationView)JSONObject.toBean(JSONObject.fromObject(SubmitOperationView),SubmitOperationView.class));
    }


}
